using System.ComponentModel.DataAnnotations;

namespace MauiBuilder.Models;

/// <summary>
/// 支付类型枚举
/// </summary>
public enum PaymentType
{
    /// <summary>
    /// 支付宝
    /// </summary>
    Alipay,
    
    /// <summary>
    /// 微信支付
    /// </summary>
    WeChatPay
}

/// <summary>
/// 支付状态枚举
/// </summary>
public enum PaymentStatus
{
    /// <summary>
    /// 待支付
    /// </summary>
    Pending,
    
    /// <summary>
    /// 支付中
    /// </summary>
    Processing,
    
    /// <summary>
    /// 支付成功
    /// </summary>
    Success,
    
    /// <summary>
    /// 支付失败
    /// </summary>
    Failed,
    
    /// <summary>
    /// 支付取消
    /// </summary>
    Cancelled,
    
    /// <summary>
    /// 支付超时
    /// </summary>
    Timeout,
    
    /// <summary>
    /// 已退款
    /// </summary>
    Refunded
}

/// <summary>
/// 支付请求模型
/// </summary>
public class PaymentRequest
{
    /// <summary>
    /// 订单号
    /// </summary>
    [Required]
    public string OrderId { get; set; } = string.Empty;
    
    /// <summary>
    /// 支付金额（单位：分）
    /// </summary>
    [Required]
    [Range(1, int.MaxValue, ErrorMessage = "支付金额必须大于0")]
    public decimal Amount { get; set; }
    
    /// <summary>
    /// 商品标题
    /// </summary>
    [Required]
    public string Subject { get; set; } = string.Empty;
    
    /// <summary>
    /// 商品描述
    /// </summary>
    public string Body { get; set; } = string.Empty;
    
    /// <summary>
    /// 支付类型
    /// </summary>
    public PaymentType PaymentType { get; set; }
    
    /// <summary>
    /// 回调通知URL
    /// </summary>
    public string? NotifyUrl { get; set; }
    
    /// <summary>
    /// 同步返回URL
    /// </summary>
    public string? ReturnUrl { get; set; }
    
    /// <summary>
    /// 超时时间（分钟）
    /// </summary>
    public int TimeoutMinutes { get; set; } = 30;
    
    /// <summary>
    /// 扩展参数
    /// </summary>
    public Dictionary<string, string> ExtendParams { get; set; } = new();
}

/// <summary>
/// 支付响应模型
/// </summary>
public class PaymentResponse
{
    /// <summary>
    /// 是否成功
    /// </summary>
    public bool IsSuccess { get; set; }
    
    /// <summary>
    /// 订单号
    /// </summary>
    public string OrderId { get; set; } = string.Empty;
    
    /// <summary>
    /// 交易号
    /// </summary>
    public string? TradeNo { get; set; }
    
    /// <summary>
    /// 支付状态
    /// </summary>
    public PaymentStatus Status { get; set; }
    
    /// <summary>
    /// 消息
    /// </summary>
    public string? Message { get; set; }
    
    /// <summary>
    /// 错误消息
    /// </summary>
    public string? ErrorMessage { get; set; }
    
    /// <summary>
    /// 错误代码
    /// </summary>
    public string? ErrorCode { get; set; }
    
    /// <summary>
    /// 支付数据（用于调起支付）
    /// </summary>
    public string? PaymentData { get; set; }
    
    /// <summary>
    /// 支付信息
    /// </summary>
    public string? PaymentInfo { get; set; }
    
    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime CreateTime { get; set; } = DateTime.Now;
    
    /// <summary>
    /// 扩展数据
    /// </summary>
    public Dictionary<string, object> ExtendData { get; set; } = new();
}

/// <summary>
/// 支付结果模型
/// </summary>
public class PaymentResult
{
    /// <summary>
    /// 是否成功
    /// </summary>
    public bool IsSuccess { get; set; }
    
    /// <summary>
    /// 订单号
    /// </summary>
    public string OrderId { get; set; } = string.Empty;
    
    /// <summary>
    /// 交易号
    /// </summary>
    public string? TradeNo { get; set; }
    
    /// <summary>
    /// 支付金额
    /// </summary>
    public decimal Amount { get; set; }
    
    /// <summary>
    /// 支付状态
    /// </summary>
    public PaymentStatus Status { get; set; }
    
    /// <summary>
    /// 支付时间
    /// </summary>
    public DateTime? PayTime { get; set; }
    
    /// <summary>
    /// 消息
    /// </summary>
    public string Message { get; set; } = string.Empty;
    
    /// <summary>
    /// 错误消息
    /// </summary>
    public string? ErrorMessage { get; set; }
    
    /// <summary>
    /// 原始响应数据
    /// </summary>
    public string? RawData { get; set; }
}

/// <summary>
/// 支付配置模型
/// </summary>
public class PaymentConfig
{
    /// <summary>
    /// 应用ID
    /// </summary>
    public string AppId { get; set; } = string.Empty;
    
    /// <summary>
    /// 商户ID
    /// </summary>
    public string MerchantId { get; set; } = string.Empty;
    
    /// <summary>
    /// 私钥
    /// </summary>
    public string PrivateKey { get; set; } = string.Empty;
    
    /// <summary>
    /// 公钥
    /// </summary>
    public string PublicKey { get; set; } = string.Empty;
    
    /// <summary>
    /// API密钥
    /// </summary>
    public string ApiKey { get; set; } = string.Empty;
    
    /// <summary>
    /// 环境配置
    /// </summary>
    public string Environment { get; set; } = "sandbox";
    
    /// <summary>
    /// 是否沙箱环境
    /// </summary>
    public bool IsSandbox { get; set; } = true;
    
    /// <summary>
    /// 签名类型
    /// </summary>
    public string SignType { get; set; } = "RSA2";
    
    /// <summary>
    /// 字符集
    /// </summary>
    public string Charset { get; set; } = "UTF-8";
    
    /// <summary>
    /// 格式
    /// </summary>
    public string Format { get; set; } = "JSON";
    
    /// <summary>
    /// 版本
    /// </summary>
    public string Version { get; set; } = "1.0";
    
    /// <summary>
    /// 支付类型
    /// </summary>
    public PaymentType PaymentType { get; set; }
    
    /// <summary>
    /// 扩展数据
    /// </summary>
    public Dictionary<string, object> ExtendData { get; set; } = new();
}